
package privatemessanger;
import javax.swing.*;
import java.awt.Color;

/**
 * This panel contains a list of online contacts.
 * @author  Erez Fatal, Oren Slor, Elad Yanai, Sigal Agami, Chen Ben Shabat,
 *          Inbar Pardo, Islamm Heralla, Ziv Hadary, Oren Shalev, Ortal David.
 */
public class ContactNamePanel extends JPanel
{
    private Client _selectedClient;
    private MainFrame _frame; // the frame.
    private DefaultListModel _listModel;
    private JList _list;

    /**
     * This is the ContactNamePanel constructor.
     * @param frame The frame which creates this panel.
     */
    ContactNamePanel(MainFrame frame)
    {
        _frame=frame;
        setBackground(Color.LIGHT_GRAY);
        _listModel = new DefaultListModel();

        //Create the list and put it in a scroll pane.
        _list = new JList(_listModel);
        _list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        _list.setSelectedIndex(0);
        _list.addListSelectionListener(_frame);
        _list.setVisibleRowCount(37);
        _list.setFixedCellWidth(175);
        _list.setBackground(new Color(190, 231, 249));
        JScrollPane listScrollPane = new JScrollPane(_list);
        listScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(listScrollPane);
    }

    /**
     * Get the list.
     * @return the list.
     */
    public JList getList() { return _list; }

    /**
     * Get the list model.
     * @return The list model.
     */
    public DefaultListModel getListModel() { return _listModel; }

    /**
     * Get the selected client on the list.
     * @return The client.
     */
    public Client getSelectedClient() { return _selectedClient; }

    /**
     * Set the selected client on the list.
     * @param The client.
     */
    public void setSelectedClient(Client client) { _selectedClient=client; }

    /**
     * Clean the selected client on the list.
     */
    public void cleanSelectedClient() { _selectedClient=null; }
}
